<?php
namespace app\common\model;
use think\Db;
/**
 * 地区模型
 */
class Area extends Base {
	/**
	 * 列表-客户管理，添加客户地址时用
	 */
	public function listQuery($parentId = 0){
		// $parentId = input('parentId',0);
		$where[] = ['dataFlag','=',1];
		$where[] = ['parentId','=',$parentId];
		$rs = $this->where($where)
			->field('areaId,areaName')
			->order('areaId','asc')
			->select();
		return $rs;
	}
	/**
	 * 检测是否还存在下级
	 */
	public function hasChild($areaId){
		return $this->where(['parentId'=>(int)$areaId,'dataFlag'=>1,'isShow'=>1])->find();
	}
	/**
	 * 获取省市县名称-店铺地址用
	 */
	public function getAreaNames($areaIdPath){
		if($areaIdPath == '')return '';
		$areaIds = str_replace("_",",",substr($areaIdPath, 0, -1));
		$rs = $this->where("dataFlag=1 and areaId in(".$areaIds.")")->column('areaName');
		if(!empty($rs)){
			return implode('',$rs);
		}
	}
}